<template>
<div class="article-list">
    <div class="wrapper">
      <!-- 循环获取的数据 -->
      <div v-for="item in data" :key="item.art_id" class="box-style">
        <!-- 判断语句 -->
        <div v-if="item.cover.type > 1">
          <div class="first">
            {{ item.title }}
            <br>
          </div>
          <!-- 循环图片 -->
          <img v-for="(image, i) in item.cover.images" :key="i" class="photo" :src="image">
          <br>
          <!-- 文字排列 -->
          <div class="style">
            {{ item.aut_name }}
            {{ item.comm_count }}评论
            {{ getTime(item.pubdate) }}
          </div>
        </div>
        <!-- 判断语句 -->
        <div v-else class="second">
          <!-- 文字排列 -->
          <div class="second-title">
            {{ item.title }}
            <br><br><br>
            <div class="style">
              {{ item.aut_name }}
              {{ item.comm_count }}评论
              {{ getTime(item.pubdate) }}
            </div>
          </div>
          <!-- 循环图片 -->
          <img v-for="(image, i) in item.cover.images" :key="i" class="photo" :src="image">
        </div>
      </div>
    </div>
</div>
</template>

<script>
import moment from 'moment';
export default {
  name: 'ArticleList',
  props: {
    data: {
      type: Array,
      default () {
        return [];
      },
    },
  },

  methods: {
    getTime(timestamp) {
      return moment(timestamp).fromNow();
    },
  },
  // data() {
  //   return {

  //   };
  // },


}
</script>

<style lang="less" scoped>
.wrapper {
  height: calc(100% - 44px);
  overflow: auto;
}
.box-style {
  display: flex;
  flex-direction: column;
  padding: 10px;
}
.second {
  display: flex;
  flex-direction: row;
}
.first {
  flex: 1;
  margin-bottom: 10px;
  width: 100%;
  overflow: hidden;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  word-break: break-all;
  margin-right: 20px;

}
.second-title {
  width: 100%;
  overflow: hidden;
  // -webkit-line-clamp: 2;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  word-break: break-all;
}
.photo {
    flex: 1;
    width: 110px;
    height: 90px;
    border-radius: 5px;
    margin-right: 5px;
}
.style {
  font-size: 13px;
  color: #999;
}

.box {
  position: relative;
}

.menu {
  font-size: 30px;
  text-align: center;
  line-height: 44px;
  position: absolute;
  right: 0px;
  top: 0px;
  width: 44px;
  height: 44px;
  background-color: white;
}

.find {
  font-size: 30px;
  text-align: center;
  line-height: 44px;
  position: absolute;
  right: 44px;
  top: 0px;
  width: 44px;
  height: 44px;
  background-color: white;
}

.shadow {
  position: absolute;
  right: 88px;
  top: 0px;
  width: 20px;
  height: 44px;
  background-image: linear-gradient(to right, rgba(255, 255, 255, 0.2), white);
}
</style>
